package com.yyq.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author yyq
 * @create 2021-08-02 19:32
 */
public class SaleFrame implements java.lang.Runnable {

     static private int ticket=100;
     public static Object object=new Object();
     private  final ReentrantLock lock=new ReentrantLock();
    @Override
    public void run() {
        int i=0;

            while (true) {
                i++;
                lock.lock();
                if(ticket > 0){
                System.out.println(Thread.currentThread().getName() + "票号" + ticket );
                ticket--;
                lock.unlock();
            }
        }
    }
}

class buyticket{
    public static void main(String[] args) {
        SaleFrame one=new SaleFrame();

        Thread one_th=new Thread(one);
        Thread two_th=new Thread(one);
        one_th.setName("售票窗口一");
        two_th.setName("售票窗口二");
        one_th.start();
        two_th.start();
    }
}
